package com.ourteam.education.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ourteam.education.dao.StudentDAOQueryBean;
import com.ourteam.education.domain.StudentBean;
import com.ourteam.education.service.IStudentManageService;
import com.ourteam.frame.controller.AbstractCRUDServiceController;

@Controller
@CrossOrigin
@RequestMapping("/api/EDUCATION/student")
public class StudentManageAPI
		extends AbstractCRUDServiceController<StudentDAOQueryBean, StudentSearchBean, StudentBean> {

	@Autowired
	private IStudentManageService studentService;

	@Override
	protected StudentDAOQueryBean newQueryBean() {
		return new StudentDAOQueryBean();
	}

	@Override
	protected int queryCount(StudentDAOQueryBean queryBean) throws Exception {
		return studentService.queryStudentCount(queryBean);
	}

	@Override
	protected StudentBean[] queryData(StudentDAOQueryBean queryBean) throws Exception {
		return studentService.queryStudents(queryBean);
	}

	@Override
	protected void deleteData(long[] ids) throws Exception {

		studentService.deleteStudents(ids);

	}

	@Override
	protected StudentBean getDataById(long id) throws Exception {
		return studentService.getStudentById(id);
	}

	@Override
	protected void saveData(StudentBean dataBean) throws Exception {
		if (dataBean.getId() == 0) {
			studentService.addNewStudent(dataBean);
		} else {
			studentService.modifyStudent(dataBean);
		}

	}

}
